Codes
Code your ideas for understanding of natural systems
Updated at 2020.11.01
Updated at 2020.10.04
Intro
블레이져에서 웹의 레이아웃을 컨트롤하는 방법은 상당히 직관적이고 쉽다. 앞으로는 콘텐츠에만 신경을 쓰라는 것 같다. 참고 사이트: Blazor University - Layouts
Files and Formats
파일 내용 및 형식
- Layout Razor 파일은 LayoutComponentBase class로부터 상속 받아야 함 (
@inherits LayoutComponentBase) - 내용이 나타나야할 위치에
@Body를 놓으면 됨 (Body는LayoutComponentBaseClass의 Property임)
@inherits LayoutComponentBase
<div class="main">
<header>
<h1>This is the header</h1>
</header>
<div class="content">
@Body
</div>
<footer>
This is the footer
</footer>
</div>
wwwroot\index.html페이지의<app>태그 요소(Tag Element) 부분에 Layout 파일의 내용이 나타남
Default Layout file
디폴트 레이아웃 파일 (MainLayout.razor)
- 기본적으로 만들어진 Layout는
/Shared/MainLayout.razor파일임 - 각각의 웹페이지 파일(Components, *.razor) 에 명시적으로 Layout을 지정하지 않으면 MainLayout이 적용됨
- 명시적으로 Layout을 지정하는 방법은 한 줄짜리 코드를 추가하면 됨:
@layout MainLayout
How to assign default layout in each folder
각 폴더별로 기본 Layout를 지정하는 방법
/Shared폴더내에 원하는 내용의 Layout 파일을 만듦 (여기서는AdminLayout.razor라고 하자). 만드는 방법은 위의 예시 참고하면 됨.예를 들어
Pages폴더 아래Admin폴더를 만들고 그 폴더 내에_Imports.razor파일을 만들고 하기와 같은 코드를 추가하면 됨.@layout AdminLayout위와 같이 하면
Admin폴더 내의 모든 razor파일에AdminLayout.razorLayout이 다 적용됨
Making Nested Layout
Layout 파일에 Layout을 포함시키면 Layout안에 또 다른 Layout을 지정할 수 있다. AdminLayout.razor를 하기와 같이 수정하면 MainLayout 속에 AdminLayout이 포함되어 나타난다.
@inherits LayoutComponentBase
@layout MainLayout
<h1>Admin</h1>
@Body
총 17 개의 글이 있습니다.
| # | 제목 | 날짜 | 조회수 |
|---|---|---|---|
| 01 | CS 배우기 요약 | 2021/06/07 | 300 |
| 02 | CS Statements | 2021/06/07 | 261 |
| 03 | 퍼셉트론 | 2021/04/15 | 262 |
| 04 | Blazor and Sqlite | 2021/04/15 | 331 |
| 05 | Blazor Layouts | 2021/04/15 | 305 |
| 06 | CS Language Reference | 2021/06/07 | 311 |
| 07 | VSCode and Markdown | 2021/04/15 | 285 |
| 08 | Blazor에서 이미지파일 다루기 | 2021/06/10 | 407 |
| 09 | Blazor and Markdown | 2021/04/15 | 396 |
| 10 | 종속성 주입 | 2021/06/07 | 290 |
| 11 | Blazor에서 데이터 다루기 | 2021/06/07 | 290 |
| 12 | Blazor Components | 2021/04/15 | 289 |
| 13 | CS Glossary | 2021/06/07 | 300 |
| 14 | Enum 타입 다루기 | 2021/12/14 | 308 |
| 15 | 생활코딩 CS01 | 2022/04/25 | 468 |
| 16 | 생활코딩 CS02 | 2022/04/30 | 368 |
| 17 | 생활코딩 CS03 | 2022/04/30 | 712 |